package com.liao.product.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liao.common.utils.PageUtils;
import com.liao.common.utils.Query;

import com.liao.product.dao.ProductAttributeDao;
import com.liao.common.entity.product.ProductAttributeEntity;
import com.liao.product.service.ProductAttributeService;


@Service("productAttributeService")
public class ProductAttributeServiceImpl extends ServiceImpl<ProductAttributeDao, ProductAttributeEntity> implements ProductAttributeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ProductAttributeEntity> productAttributeEntityQueryWrapper = new QueryWrapper<>();

        String key= (String) params.get("key");

        if (!StringUtils.isEmpty(key)){
            System.out.println("key"+key);
            productAttributeEntityQueryWrapper.eq("attribute_id",key).or().eq("product_id",key).or().like("attribute_name",key).or().like("attribute_value",key);
        }

        IPage<ProductAttributeEntity> page = this.page(
                new Query<ProductAttributeEntity>().getPage(params),
                productAttributeEntityQueryWrapper
        );

        return new PageUtils(page);
    }

}